import React, { Component } from "react";

// 处理多个输入
class App extends Component {
  state = {
    checked: true,
    value: "(*^_^*)",
  };
  handleChange = (e) => {
    // console.log(e);
    console.log(e.target.dataset);
    let target = e.target.dataset.target;
    // if (e.target.dataset.target === "checked") {
    //   this.setState({
    //     [target]: e.target.checked,
    //   });
    // } else {
    //   this.setState({
    //     [target]: e.target.value,
    //   });
    // }
    this.setState({
      [target]: target === "checked" ? e.target.checked : e.target.value,
    });
  };
  render() {
    return (
      <div>
        <input
          type="checkbox"
          data-target="checked"
          checked={this.state.checked}
          onChange={this.handleChange}
        />
        <input
          type="text"
          data-target="value"
          value={this.state.value}
          onChange={this.handleChange}
        />
      </div>
    );
  }
}

export default App;
